using System;
using System.Windows.Forms;
using System.Drawing;


namespace DrawTools
{
	/// <summary>
	/// Polygon tool
	/// </summary>
	public class ToolPolygon : ToolObject
	{
		public ToolPolygon()
		{
            Cursor = new Cursor(Common.FunctionClass.getRunPath() + @"\Resources\PolyHandle.cur");
        }

        private int lastX;
        private int lastY;
        private DrawPolygon newPolygon = null;

        /// <summary>
        /// Left nouse button is pressed
        /// </summary>
        /// <param name="drawArea"></param>
        /// <param name="e"></param>
        public override void OnMouseDown(KKDraw drawArea, MouseEventArgs e)
        {
            // Create new polygon, add it to the list
            // and keep reference to it
            if (e.Button == MouseButtons.Left)
            {
                if (newPolygon == null)
                {
                    newPolygon = new DrawPolygon(e.X, e.Y, e.X + 1, e.Y + 1);
                    AddNewObject(drawArea, newPolygon);
                }
                else
                {
                    newPolygon.AddPoint(e.Location);
                }
            }
            else if (e.Button == MouseButtons.Right)
            {
                newPolygon = null;
                base.OnMouseUp(drawArea, e);
            }
            
            
            lastX = e.X;
            lastY = e.Y;
        }

        /// <summary>
        /// Mouse move - resize new polygon
        /// </summary>
        /// <param name="drawArea"></param>
        /// <param name="e"></param>
        public override void OnMouseMove(KKDraw drawArea, MouseEventArgs e)
        {
            drawArea.Cursor = Cursor;

            if ( e.Button != MouseButtons.Left )
                return;

            if ( newPolygon == null )
                return;                 // precaution

            Point point = new Point(e.X, e.Y);
            newPolygon.MoveHandleTo(point, newPolygon.HandleCount);
            drawArea.Refresh();
        }

        public override void OnMouseUp(KKDraw drawArea, MouseEventArgs e)
        {
        }


	}
}
